//
//  PresentingViewController.m
//  AnimationDemo
//
//  Created by jiaozenglian on 2020/7/12.
//  Copyright © 2020 Jiaozl. All rights reserved.
//

#import "PresentingViewController.h"
#import "PresentedViewController.h"
@interface PresentingViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end

@implementation PresentingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.imageView.image = [UIImage imageNamed:@"sccnn.jpg"];
    [self setupGesture];
}

- (void)setupGesture
{
    // 添加屏幕边缘滑动手势
    UIPanGestureRecognizer *screenEdgePanGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_actionLeftSwipe:)];
    [self.view addGestureRecognizer:screenEdgePanGR];
}

- (void)_actionLeftSwipe:(UIScreenEdgePanGestureRecognizer *)sender
{
    [self _actionPresentNewVC:sender];
}

- (void)_actionPresentNewVC:(id)sender
{
    if ([sender isKindOfClass:UIGestureRecognizer.class] ) {
        if (((UIGestureRecognizer *)sender).state == UIGestureRecognizerStateBegan) {
            [self _actionPresent:sender];
        }
    } else {
        [self _actionPresent:sender];
    }
}

- (IBAction)_actionPresent:(id)sender
{
    PresentedViewController *toVC = [PresentedViewController new];
    if ([sender isKindOfClass:UIGestureRecognizer.class] ) {
        toVC.gestureRecognizer = sender;
    } else {
        toVC.gestureRecognizer = nil;
    }
    [self presentViewController:toVC animated:YES completion:nil];
}


@end
